home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload Trio 2
/
Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO
/
dir35
/
!tsgrep.zip
/
TSGREP.DOC
< prev
next >
Wrap
Text File
|
1993-05-04
|
23KB
|
567 lines
/****************************************************************************
TSGREP ... A regular expression line extractor
David Marcus
****************************************************************************
Version 4.6
**************
Copyright: 1993 David Marcus
Permission is granted to all persons for non-commercial
distribution of this file and the macros and ideas contained
herein provided (a) credit is given to the author and (b) all
changes not made by the author are attributed.
Permission is granted to SemWare for commercial distribution
provided (a) and (b) above.
Author: David Marcus
Date: 4-27-93
Description:
TSGREP is a line extractor that searches groups of files
and lists line matching a search string.
Installation:
1. Place TSGREP.S in the directory where your macro source files reside.
2. (optional; required for command line operation only) Place TSGREP.BAT
in a directory on your path. If your copy of TSE is not named e.exe,
edit TSGREP.BAT to change the name from e to whatever you use.
3. Advanced Users: In TSGREP.S, the string ':U:' appears on each line
that contains the initial setting of a toggle or mode. Search for :U:
and customize as you like.
4. Compile TSGREP using sc:
sc TSGREP
Usage Notes:
■ Contents:
Quick Start
Current option summary
Current special character summary
Enhancements since first version, backwards by date.
How to use TSGREP. (May not include all enhancements.)
TSGREP.BAT
■ Quick Start
Type TSGREP at the command line.
You give TSGREP:
* a search string
* filespec(s) to search
* search options
* the name of a temp file to create
TSGREP gives you:
* A file that includes each line with the search string on it
* The ability to press ctrl+enter to go to load the file and
go to line listed at the current cursor position. You can
then press ctrl+enter to go back to the list file.
* Help when you press alt+h.
Bells & Whistles:
* TSGREP shows on-screen help for each prompt.
* You can run TSGREP from the command line, specifying all
arguments on the command line. Type TSGREP /H for syntax
help.
* You can specify searching of files in subdirectories of the
one that is part of the search filespec.
* If you enter multiple filespecs, and one or more don't have
a drive or path, TSGREP uses the drive and path with the
prevous spec. For instance, if you say to search
"i:\usr\both\*.asc" and also "*.doc", TSGREP searches
"i:\usr\both\*.asc" and also "i:\usr\both\*.doc".
* You can specify files to never search as within TSGREP'
source code or as part of the batch file. (TSGREP is preset
to ignore .img .exe .com .dll .tif .pcx .$hp .$sc .cif &
.vgr in its source code, and .bak & .$hp in the batch file.
* You can use "-or-" or "-and" in your search string without
using regular expression syntax.
* TSGREP automatically searches any loaded files, but never
leaves more files loaded than you started with.
* You can run TSGREP from the DOS prompt using the batch file
TSGREP.BAT to skip all prompts. TSGREP.BAT is contained at the
end of this file.
* TSGREP processes "list files" - files containing a list of
files or file specs to process.
* When you are looking at the list file TSGREP produces, you
can toggle to seeing only file names or file names + hits.
You can remove a file and its entries from the list ... and
later restore all removed files - they are again part of the
list. You can use alt+p and alt+n to directly to the previous
or next file in the listing. And you can use alt+h for help.
■ Current option summary (in addition to SE std options):
\# - don't include line numbers
\_ - don't convert underscores in search string to spaces
\l - [lower case "el"] don't load outfile
\1 - [numeral "one"] don't find more than 1 hit per file
\w - don't write copy of lines with hits to outfile;
only list file names
\x - don't kick in regular expression search automatically
The following SE find options are either always ignored or always
used by TSGREP; do not use them: b, g, l, +.
■ Current special character summary:
Search string:
-or- means | ("or")
-and- means "and"
_ means " "
\- means "="
[[ means "<"
]] means ">"
Input file spec:
+ (at end) - recursive directory searching
^ - connects two separate file specs
@ - part of list file name
All special characters in searchstring and in options are user-configurable.
■ Current keystroke summary:
Keystrokes while in file listing hits:
<alt F> Toggle showing lines with hits or only filenames
<alt N> Goto next file in listing
<alt P> Goto prev file in listing
<alt R> Remove the entries for a file
<alt U> Undo all removes
<alt enter> Edit file/line cursor is on
<alt esc> Save outfile and exit
<alt h> Help
<alt -> Unload TSGREP
Keystrokes while editing one of the files listed:
<alt N> Goto next hit in file
<alt P> Goto prev hit in file
<alt escape> Exit
<alt enter> Go back to the file listing hits
<alt h> Help
<alt -> Unload TSGREP
────────────────────────────────────────────────────
■ 5-4-93 When interactively run and query saves is set to TRUE,
TSGREP now checks each file and, if changed, queries whether
to save changes or not. If not files are changed, no query is
performed.
■ 12-22-92 Fixed bug where loaded files were not being saved when the
query_saves flag was set to NO.
TSGREP will prompt for all arguments, and show help for each,
when started like this:
C:> e -eTSGREP
TSGREP.BAT now allows for this; just type TSGREP to start it
this way. (I recommend you replace your SGRP.BAT with the one
in this ZIP file.)
The files-only buffer is now saved as the filename defined as
default_name_2. This is not particularly desireable, but
necessary. Note that the unload function will delete this file
from disk.
Changed help for keystrokes so that (a) it pops up whenever
<alt h> is hit and (b) it does not pop up automatically when
TSGREP is done.
Added <alt -> to unload TSGREP. All buffers used by TSGREP are
freed except the one containing the output file. Keys revert
to pre-TSGREP assignments.
Added an integer for the normal attribute and the hilite
attribute to be used by TSGREP. These are defined as
normal_attr = Query(TextAttr) // attribute for normal text
normal_attr = Query(HiLiteAttr) // attribute for highlighting
If you have TSE configured to use the same attributes for
these two items, change one of these items. Also do this if
you ahve one of them set to blink!
NOTE: These are found at the beginning of Main().
■ 12-21-92 For Tom Hogshead: The characters written before and after
each file name are now configurable:
name_prefix[4] = ' ', // inserted into outfile before name
name_suffix[4] = ': ', // inserted into outfile after name
name_prefix_re[8] = '' // version of above with and regexp
// characters escaped out (created by
// TSGREP)
Note that name_prefix_re must be double the length
of name_prefix.
■ 12-20-92 For Tom Hogshead: TSGREP now operates while in an edit
session. Help is provided for each input option. As a result,
TSGREP is now approximately 11k. (To reduce the size of TSGREP,
edit ask_input() to remove the help text.)
Files currently in the ring are always searched. Files added for
filespec prompt are searched additionally.
Files in the ring are unloaded after being searched (to prevent
any VM slows). Each is saved to disk first. If you set the
integer query_flags to TRUE, the save will be queried; if you
don't save, TSGREP aborts.
Files in the ring are reloaded after TSGREP finishes. Current
row is restored for each.
Note: If the environment variable SSTRING is set (to
anything), TSGREP assumes that you do NOT want to be
prompted for the arguments, and executes using
environment variables (without prompting). So, be sure
that your batch file resets SSTRING to '' after
execution.
You can start TSGREP in batch. Then, with the outfile loaded
(or any other), you can restart it (via execmacro) and it will
prompt you for values.
■ 12-18-92 No longer uses List() to display files.
Keystrokes and specific functions added; see above,
Added ++ to mean "AND" in the search string. May be only used
once in the string. Order is not important; a++b means (a.*b or
b.*a) ... and that is exactly how it is implemented.
If combining OR with AND, use braces to surround the terms
being ORd; results will be unpredictable otherwise. For instance
if you use this:
sort++{search-or-subtotal}
TSGREP will it interpret it as:
{{sort.*{search}|{subtotal}} | {{search}|{subtotal}.*sort}}
(spaces added for clarity)
■ 12-14-92 Made a change to speed recursive directory searching slightly.
However, TSGREP now does not search directories that have
extensions as part of the file name (created by a command such
as "MKDIR C:\SE.62"). If you have directories such as that and
you wish them search, change the line
dir_spec = '*.',
to
dir_spec = '',
This is in the global string definitions section.
■ 12-11-92 Added header for files with finds.
Added option (\w) to suppress the writing of lines with hits
in the output file. When this is used, TSGREP prepares a list of
files with hits but does not include the text of the hit.
Gotohit will still got to the first hit, however.
All special character in searchstring and in options are now
user configurable.
■ 12-9-92 <Escape> to abort added during processing. <escape> is checked
before each file load and before each recursive directory check.
Options are now the 3rd argument in the TSGREP batch file, and
outfile is 4th. This means that options can be used without
outfile, but must be used if outfile is to be specified.
The output file is now loaded for editing _unless_ \l
is used as an option. (The e option is no longer used.)
If the search string includes any of the strings listed below
then regular expression search is set unless \x is used as an
option:
-or-
-OR-
.*
[
++
See the definition for EXCLUDE for a set of extensions now hard-
coded in TSGREP as extensions to be ignored.
In multiple filespec processing, if a filespec has no drive and
path, the ones for the preceding filespec are applied to it.
For instance:
TSGREP searchstring i:\usr\*.txt^*.doc^c:\*.txt^*.doc
is processed as
TSGREP searchstring i:\usr\*.txt^i:\usr\*.doc^c:\*.txt^c:\*.doc
■ 12-5-92 Recent changes include recursive searching of subdirectories,
initiated by adding a "+" to the end of any filespec or entry in a
listfile.
When '-or-' or '-OR-' is used in a regular expression search,
braces are added automatically. For instance:
TSGREP sort-or-search
is processed as
TSGREP {sort}|{search}
Use \1 as a search option to stop searching each file after
1 hit found.
TSGREP now attempts to not load any file whose extension matches a
list in an environment variable (and never searches these files).
/───────────────────────────────────────────────────────────────────────
■ How to Use TSGREP
──────────────────
1. While in an edit session:
Just load and execute like any other macro.
You'll be prompted for the information TSGREP needs.
Note that if the environment variable SSTRING is set (to anything),
TSGREP assumes that you do NOT want to be prompted for the arguments,
and executes using values from the DOS environment. So, be sure that
your batch file resets SSTRING to '' after execution.
2. Use TSGREP in a batch file, named (I hope) TSGREP.bat, as follows:
C:> TSGREP searchstring filespec [options [outfile]]
3. Using TSGREP in a batch file, named (I do hope) TSGREP.BAT, as follows:
D:> TSGREP
Executing TSGREP from the DOS command line:
D:> E -eTSGREP <enter>
In either case, TSGREP prompts for all arguments, showing help for each
as it prompts.
You can start TSGREP with the batch file. Then, with the outfile loaded
(or any other), you can restart it (via execmacro) and it will prompt
for values. I myself have it tied to <alt s><g>:
<alt S> <g> Execmacro('sgrep')
■ Search String
───────────────
Your search string may be any QEdit search string.
However:
* Use -or- instead of | to avoid DOS piping. -OR- is ok, too. [1]
* If -or- is NOT surrounded by }{, TSGREP will supply the braces. So,
menu-or-proc-or-keydef
gets turned into
{menu}|{proc}|{keydef}
All braces you supply will be honored, too.
* Use _ instead of space. [1]
(Use \_ in options to force reading of _ as an underscore)
* Use \- for = [1]
* Use ++ to mean "AND" in the search string. May be only used
once in the string. Order is not important; a++b means (a.*b or
b.*a) ... and that is exactly how it is implemented.
If combining OR with AND, use braces to surround the terms
being ORd; results will be unpredictable otherwise. For instance
if you use this:
sort++{search-or-subtotal}
TSGREP will it interpret it as:
{{sort.*{search}|{subtotal}} | {{search}|{subtotal}.*sort}}
(spaces added for clarity)
* Use [[ to mean < in the search string. [1]
Use ]] to mean > in the search string. [1]
NOTE: [1] Required when entering the search string from the DOS command
line.
■ Input File Spec
─────────────────
Infile may be any valid filespec, wildcards included.
When TSGREP operates during an edit session, files currently in the ring are always
searched. Files specified at the filespec prompt are searched
additionally; the original ring is restored after the searches, and no
additional files are left loaded.
Use ^ as a separator for multiple files, as in:
TSGREP sort *.q^*.inc^q:c*.??c
In multiple filespec processing, if a filespec has no drive and
path, the ones for the preceding filespec are applied to it.
For instance:
TSGREP searchstring i:\usr\*.txt^*.doc^c:\*.txt^*.doc
is processed as
TSGREP searchstring i:\usr\*.txt^i:\usr\*.doc^c:\*.txt^c:\*.doc
Files with '@' in any position of the name are treated as list files.
List files may contain:
* specific file names
* wildcarded filespecs
* additional listfile names
Place one spec per line, starting each in column 1.
You can use multiple list files on the command line or combine them
with other filespecs.
Add a plus sign to the end of a filespec to have TSGREP process
matching files in subdirectories of the specified one. You can use
the plus sign both in filespecs and inside listfiles. TSGREP builds its
list of subdirectories once for each plus sign you use, so it may be more
efficient to use other strategies than this.
Also, if you use this feature, be *sure* to set the variable RAMDRIVE.
As a by-product, the command
tsgrep .* c:\nul+ \w
generates a list of all directories on your disk.
TSGREP ignores any files whose extension is found in the list specified by
the environment variable EXCLUDE or the definition of the string
EXCLUDE.
NOTES: 1. You cannot use the ^ separator inside a list file.
2. List files must actually have the @ as part of the file name.
3. TSGREP now not search directories that have extensions as part
of the file name (created by a command such as "MKDIR C:\SE.62").
If you have directories such as that and you wish them searched,
change the line
dir_spec = '*.',
to
dir_spec = '',
This is in the global string definitions section.
■ Search Options
────────────────
Options may be any QEdit search options except 'b', 'g' and '+'. (These
are used automatically, as appropriate, and are screened out of options
you enter.)
Default options are 'i'. If any of these strings are contained in the
search string, 'x' is automatically added to the options unless '\x'
is used as an option:
-or-
.*
[
++
Use \# in options to suppress line numbers.
Use \1 to stop searching each file after 1 hit found [that's the numeral
"one"].
Use \_ to force reading of '_' in the search string as underscores
rather than spaces.
Use \l to suppress loading of t load outfile [that's a lowercase "el"].
Use \w to not write lines with hits to outfile; only list file names
Use \x to overide automatic kick in of regular expression.
■ Outfile
──────────
Outfile is optional; default is TSGREP.TMP or as set by the
default_name string.
Files with no hits are listed at the end of outfile.
■ Usage Notes
─────────────
Keystrokes while in the file listing hits:
<alt F> Toggle showing lines with hits or only filenames
<alt N> Goto next file in listing
<alt P> Goto prev file in listing
<alt R> Remove the entries for a file
<alt U> Undo all removes
<alt enter> Edit file/line cursor is on
<alt esc> Save outfile and exit
Keystrokes while editing one of the files listed:
<alt N> Goto next hit in file
<alt P> Goto prev hit in file
<alt escape> Exit
<alt enter> Go back to the file listing hits
To have files searched in alpha order [OR any particular order],
use an @listfile with the files in the desired order.
Use <Escape> to abort during processing. <escape> is checked before each
file load and before each recursive directory check. Give it a few
seconds to kick in if you use it.
When TSGREP operates during an edit session, files currently in ring are
always searched. Files added for filespec prompt are searched
additionally. The files in the ring are unloaded after being searched
(to prevent any VM slows). Each is saved to disk first. If you set the
integer query_flags to TRUE, the save will be queried; if you don't
save, TSGREP aborts. Files in the ring are reloaded after TSGREP finishes.
Current line is restored for each.
■ TSGREP.BAT
@echo off
rem Usage:
rem TSGREP string infile [options [outfile]]
if "%1"== "" goto :prompt_user
if "%1"== "?" goto :help
if "%2"== "" goto :help
set string=%1
set infile=%2
set options=%3
set outfile=%4
set exclude=" .bak .$hp"
:prompt_user
q:\e -eq:\TSGREP
goto end
:help
echo ┌──────────────────────────────────────────────────────────────────────┐
echo │ Usage: │
echo │ TSGREP [searchstring infile [outfile [options]]] │
echo ╞══════════════════════════════════════════════════════════════════════╡
echo │ If no arguments given, TSGREP prompts for each one. │
echo │ Searchstring may be any QEdit searchstring. │
echo │ * Use -OR- instead of as the 'OR' indicator in expressions │
echo │ * Use -OR- instead of as the 'OR' indicator in expressions │
echo │ * Braces optional; default parsing supplied │
echo │ * Use \- instead of = │
echo │ * Use _ instead of space │
echo │ Infile may be any valid filespec, wildcards included. │
echo │ Files with '@' in the name are treated as list files. │
echo │ Add + to the end of the filesspec for recursivce search. │
echo │ List files may be nested to 3 levels; possibly more will work. │
echo │ Use ^ as a separator for multiple files, as in │
echo │ TSGREP sort *.q^*.inc^who.??q │
echo │ Search options may be any QEdit search options except 'b'. │
echo │ * An additional TSGREP option is 'e', 'edit the outfile'. │
echo │ * Default options = 'ei'' │
echo │ * if only 'e' entered, options set to 'ei' │
echo │ * Use \# in options for suppress line numbers │
echo │ * Use 1 in options to stop searching each file after 1 hit │
echo │ Outfile is optional; default is TSGREP.TMP │
echo └──────────────────────────────────────────────────────────────────────┘
:end
set string=
set infile=
set outfile=
set options=
set exclude=
────────────────────────────────────────────────────────────────────────── */